import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '停车管理系统', icon: 'dashboard' }
    }]
  },

  {
    path: '/park',
    component: Layout,
    // redirect: '/system',
    name: '车位管理',
    meta: { title: '车位管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/park/index',
        name: '车位列表',
        component: () => import('@/views/park/index.vue'),
        meta: { title: '车位列表', icon: 'table' },

      },
      {
        path: '/admin/edit',
        component: () => import('@/views/system/admin/edit.vue'),
      },

    ]
  },
  {
    path: '/system',
    component: Layout,
    // redirect: '/system',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/admin/list',
        name: '管理员列表',
        component: () => import('@/views/system/admin/list.vue'),
        meta: { title: '管理员列表', icon: 'table' },

      },
      {
        path: '/user/list',
        name: '用户管理',
        component: () => import('@/views/system/user/list.vue'),
        meta: { title: '用户管理', icon: 'table' }
      },

    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
